var express = require('express');
var router = express.Router();
var mysql = require('mysql');
const { mysqlCreate } = require('./utils');

//连接数据库
let conn = mysqlCreate();

//发送新文章
router.post('/', (req, res)=>{
  conn = mysql.createConnection(conn.config);
  const { title, content, user, type } = req.body.artData;
  var sql = `insert into article (title, content, user, type) values ('${title}', '${content}', '${user}', '${type}')`
  conn.connect();
  conn.query(sql, function(err, result){
    if(err){
      console.log(err)
      res.json({ code: -1, message: "插入失败"})
    }else{
      res.json({ code: 10000, message: "OK"})
    }
  })
  conn.end();
})


module.exports = router;
